<?php

abstract class Controller
{
	/**
	 * The internal Smarty object.
	 *
	 * @var Smarty
	 */
	protected $smarty = null;
	
	/**
	 * The privileges of the current module, specifies which usertype can access the module.
	 * 
	 * @var array
	 */
	protected $privileges = array();
	
	/**
	 * Enter description here...
	 *
	 * @var User
	 */
	protected $user = null;
	
	/**
	 * Whether or not the module requires authentication.
	 *
	 * @var boolean
	 */
	protected $requiresAuthentication = true;
	
	/**
	 * The viewmanager.
	 *
	 * @var ViewManager
	 */
	protected $views = null;
	
	/**
	 * The default constructor.
	 *
	 * @param Smarty $smarty
	 */
	public final function __construct( User $user = null, Smarty $smarty = null )
	{
		$this->smarty = $smarty;
		$this->user = $user;
		if( $this->smarty != null )
			$this->views = new ViewManager( $this->smarty );
	}
	
	public function canPerform(  )
	{
		return in_array( $this->user->getType(), $this->privileges );
	}
	
	/**
	 * Returns the internal Smarty object.
	 *
	 * @return Smarty
	 */
	public final function getSmarty()
	{
		return $this->smarty;
	}
	
	/**
	 * Returns the internal view manager.
	 *
	 * @return ViewManager
	 */
	public final function getViewManager()
	{
		return $this->views;
	}
	
	public final function requiresAuthentication()
	{
		return $this->requiresAuthentication;
	}
	
	/**
	 * Forces the implementation of a default action.
	 *
	 */
	abstract public function defaultAction(); 
}
